using System;
using HashFoo.Core;

namespace HashFoo.Rest.Common
{
    /// <summary>
    /// A client for Query and Command executions.
    /// </summary>
    /// <remarks>
    /// The client context uses individual callbacks for completed, error and canceled (jquery ajax style inspired).
    /// </remarks>
    public interface IClientContext
    {
        /// <summary>
        /// Executes a command that returns a result.
        /// </summary>
        /// <typeparam name="TResultModel"></typeparam>
        /// <param name="command"></param>
        /// <param name="completedCallback"></param>
        /// <param name="errorCallback"></param>
        /// <param name="canceledCallback"></param>
        /// <returns></returns>
        IWebClientOperation ExecuteCommand<TResultModel>(
            ICommand<TResultModel> command,
            Action<TResultModel> completedCallback,
            Action<WebRequestError> errorCallback = null,
            Action canceledCallback = null);

        /// <summary>
        /// Executes a command that does not return a result.
        /// </summary>
        /// <param name="command"></param>
        /// <param name="completedCallback"></param>
        /// <param name="errorCallback"></param>
        /// <param name="canceledCallback"></param>
        /// <returns></returns>
        IWebClientOperation ExecuteCommand(
            ICommand command,
            Action completedCallback = null,
            Action<WebRequestError> errorCallback = null,
            Action canceledCallback = null);

        /// <summary>
        /// Executes a query.
        /// </summary>
        /// <typeparam name="TResultModel"></typeparam>
        /// <param name="query"></param>
        /// <param name="completedCallback"></param>
        /// <param name="errorCallback"></param>
        /// <param name="canceledCallback"></param>
        /// <returns></returns>
        IWebClientOperation Query<TResultModel>(
            IQuery<TResultModel> query,
            Action<TResultModel> completedCallback,
            Action<WebRequestError> errorCallback = null,
            Action canceledCallback = null);

        /// <summary>
        /// Adds metadata to a query, then executes it.
        /// </summary>
        /// <typeparam name="TResultModel"></typeparam>
        /// <param name="query"></param>
        /// <param name="meta"></param>
        /// <param name="completedCallback"></param>
        /// <param name="errorCallback"></param>
        /// <param name="canceledCallback"></param>
        /// <returns></returns>
        IWebClientOperation Query<TResultModel>(
            IQuery<TResultModel> query,
            QueryMeta meta,
            Action<TResultModel> completedCallback,
            Action<WebRequestError> errorCallback = null,
            Action canceledCallback = null);
    }
}